<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./vue.js"></script>
  <script src="./vuex.js"></script>
</head>

<body>
  <div id="app">
    <button @click="mut">查看mutations接收的参数：</button>
    <button @click="act">查看actions接收的参数：</button>
  </div>

  <script>
    const store = new Vuex.Store({
      state: {
        name: "lindaihguang",
        age: "23",
        gender: "male"
      },
      mutations: {
        test(state) {
          console.log(state);
        },
      },
      actions: {
        test(context, param) {
          // console.log(context);
          console.log(param);
        }
      }
    })

    const vm = new Vue({
      el: "#app",
      store,
      methods: {
        mut() {
          // 提交一次，就相当于触发mutations里面的事件一次
          this.$store.commit("test")
        },
        act() {
          // this.$store.dispatch("test")
          // this.$store.dispatch("test", "我是传递的参数")
          // 传递对象参数必须包含type属性以及对应的属性值,type之后的就是自定义属性和属性值
          this.$store.dispatch({
            type: "test",
            name1: "我是传递的参数1",
            name2: "我是传递的参数2"
          })

        }
      }
    })
  </script>
</body>

</html>